package com.lm.service;

import com.lm.dao.UserMapper;
import com.lm.pojo.User;
import org.mybatis.spring.support.SqlSessionDaoSupport;

import java.util.List;

/**
 * 方式二：
 * 保持数据源与sqlSessionFactory不变
 * 将sqlSessionFactory注入到UserMapperImpl2中(UserMapperImpl2继承了SqlSessionDaoSupport)
 * SqlSessionDaoSupport中含有set访问器
 */
public class UserMapperImpl2 extends SqlSessionDaoSupport implements UserMapper {


    public List<User> getUserList() {
        return getSqlSession().getMapper(UserMapper.class).getUserList();
    }

    public int insert(User user) {
        return getSqlSession().getMapper(UserMapper.class).insert(user);
    }

    public User getUserById(int id) {
        return getSqlSession().getMapper(UserMapper.class).getUserById(id);
    }

    public int updateUser(User user) {
        return getSqlSession().getMapper(UserMapper.class).updateUser(user);
    }

    public int deleteUser(int id) {
        return getSqlSession().getMapper(UserMapper.class).deleteUser(id);
    }

    public User getUserByIdForMap(int id) {
        return getSqlSession().getMapper(UserMapper.class).getUserByIdForMap(id);
    }
}
